<?php
require_once 'config.php';
require_once 'common.php';
require_once 'ResultData.php';

$result = new ResultData();

$id = trim($_REQUEST['id']);
$course_id = trim($_REQUEST['course_id']);
$student_id = trim($_REQUEST['student_id']);

if ($id == "") {
    $result->code = 404;
    $result->msg = "id未填写";
    exit(json_encode($result));
}

if ($course_id == "") {
    $result->code = 404;
    $result->msg = "course_id未填写";
    exit(json_encode($result));
}
$course_id = intval($course_id);

if ($student_id == "") {
    $result->code = 404;
    $result->msg = "student_id未填写";
    exit(json_encode($result));
}
$student_id = intval($student_id);

$con = mysqli_connect($servername, $username, $password, $database, $port);

if (!$con) {
    $result->code = 404;
    $result->msg = "数据库连接不上";
    exit(json_encode($result));
}

$sql = "UPDATE t_student_course_ref SET student_id = {$student_id}, course_id = {$course_id} WHERE id = {$id}";

$con->query($sql);

mysqli_close($con);

exit(json_encode($result));
